using System;
using System.Collections;
using System.Xml.Serialization;

namespace WebApplication
{
	[Serializable]
	public class ShareCollection : ICollection
	{
		public ArrayList _aShares;	// JoeB made public so serialized

		public Share this [int index]   // indexer declaration
		{ 
			get
			{
				return (Share) _aShares[index];
			}

			set
			{
				_aShares[index] = value;
			}
		}

		public void CopyTo(Array a, int index)
		{
			_aShares.CopyTo(a, index);
		}
		public object SyncRoot
		{
			get{return this;}
		}
		public bool IsSynchronized
		{
			get{return false;}
		}

		public int Count
		{
			get
			{
				return _aShares.Count;
			}
		}

		public ShareCollection ()
		{
			_aShares = new ArrayList ();
		}

		public void Add (System.Object Share)
		{
			_aShares.Add (Share);
		}

		public void Add (Share Share)
		{
			_aShares.Add (Share);
		}

		public void Remove (Share Share)
		{
			_aShares.Remove (Share);
		}

		// IEnumerable Interface Implementation:

		public IEnumerator GetEnumerator() // non-IEnumerable version
		{
			return _aShares.GetEnumerator ();
		}

		IEnumerator IEnumerable.GetEnumerator() // IEnumerable version
		{
			//			return (IEnumerator) new ShareEnumerator(this);
			return _aShares.GetEnumerator ();
		}
	}

	[Serializable]
	public class Share
	{
		private bool			_president;
        private int _percentage;

//[XmlIgnore]
//[SoapIgnore]
        public int Percentage
        {
            get { return _percentage; }
            set { _percentage = value; }
        }
		private PublicCompany	_publicCompany;

		public Share ()
		{
		}

		public Share (int nPercentage, PublicCompany publicCompany, bool president)
		{
			_president = president;
			_percentage = nPercentage;
			_publicCompany = publicCompany;
		}
		

		public bool President
		{
			get	{ return _president; }
			set { _president = value; }
		}

		public int Price
		{
			get	{ return _publicCompany.MarketValue; }
		}
	
		//[XmlIgnore]	// fix up as back pointer on load
		public PublicCompany PublicCompany	
		{
			get { return _publicCompany; }
			set { _publicCompany = value; }
		}

	}
}
